/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.staff;

import model.Constants;
import model.personInfo.Contacts;
import model.personInfo.Name;
import model.personInfo.Origin;
import model.universityUnits.CurriculumInterface;
import model.universityUnits.GroupInterface;

/**
 * Class that represents student
 * @author Dmitri Paziy
 */
public class Student extends Person{
    private int course;
    private GroupInterface group;

    public Student(Name name, Origin origin, Contacts contacts) {
        super(name, origin, contacts);
        
        this.course = 0;
        this.group = null;
    }

    /**
     * Getter of student's course
     * @return Student's course
     */
    public int getCourse() {
        return course;
    }

    /**
     * Setter of student's course. Value must greater than 0 and lesser than
     * Constants.MAXIMUM_COURSE = {@value Constants#MAXIMUM_COURSE}
     * @param course Course of student
     * @throws IllegalArgumentException if specified course number is out of range
     * @see Constants#MAXIMUM_COURSE
     */
    public void setCourse(int course) {
        if (course <= 0 || course > Constants.MAXIMUM_COURSE) {
            throw new IllegalArgumentException("Illegal course number: " + course);
        }
        
        this.course = course;
    }

    /**
     * Getter of group, within student is studying. May be <i>null</i> if value
     * wasn't been set.
     * @return Student's group
     */
    public GroupInterface getGroup() {
        return group;
    }

    /**
     * Setter of student's group.
     * @param group Student's group
     * @throws IllegalArgumentException if specified group is <i>null</i>
     */
    public void setGroup(GroupInterface group) {
        if (group == null) {
            throw new IllegalArgumentException(Constants.NULL_ARGUMENT_MESSAGE);
        }
        
        this.group = group;
    }
    
    /**
     * Gets curriculum of student.
     * @return Student's curriculum
     * @throws NullPointerException If student wasn't been enrolled 
     */
    public CurriculumInterface getCurriculum() {
        if (group == null) {
            throw new NullPointerException("Group wasn't been set.");
        }
        
        return group.getDepartment().getFaculty().getDeneary().getGroupCurriculum(group);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Student other = (Student) obj;
        if (!super.equals(obj)) {
            return false;
        }
        if (this.course != other.course) {
            return false;
        }
        if (this.group != other.group && (this.group == null || !this.group.equals(other.group))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 53 * hash + this.course;
        hash = 53 * hash + (this.group != null ? this.group.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        final StringBuilder builder = new StringBuilder();
        
        builder.append("Student info: ");
        builder.append(Constants.LINE_SEPARATOR);
        builder.append(super.toString());
        builder.append("Course: ");
        builder.append(course);
        builder.append(Constants.LINE_SEPARATOR);
        
        builder.append("Group: ");
        if (group != null) {
            builder.append(group.getName());
        } else {
            builder.append("none");
        }
        
        return builder.toString();
    }
}
